#!/usr/bin/env python
# -*- coding:utf-8 -*-


from flask import Flask
from flask import request

app = Flask(__name__)


# 以下代码可通过postman 来测试


# request.args
# http://127.0.0.1:5000/demo1?user_id=1
@app.route("/demo1", methods=["get"])
def demo1():
    user_id = request.args.get("user_id", "")
    print("demo1 user_id:", user_id)
    return "200 ok"


# http://127.0.0.1:5000/demo2/1
@app.route("/demo2/<int:user_id>", methods=["get"])
def demo2(user_id):
    print("demo2 user_id:", user_id)
    return "200 ok"


# request.json
# http://127.0.0.1:5000/demo3
@app.route("/demo3", methods=["post"])
def demo3():
    resp = request.json
    mobile = resp.get("mobile", "")
    password = resp.get("password", "")
    print("demo3 mobile:", mobile)
    print("demo3 password:", password)
    return "200 ok"


# request.url & request.method
# http://127.0.0.1:5000/demo4
@app.route("/demo4", methods=["get"])
def demo4():
    print("demo4 request.url:", request.url)
    print("demo4 request.method:", request.method)
    return "200 ok"


if __name__ == '__main__':
    app.run(debug=True)
